//
//  SSProjectSpecificationView2.swift
//  拾舍清洁
//
//  Created by sky.wei on 2023/2/24.
//

import UIKit

class SSProjectSpecificationView2: UIView {
    
    var model:ListCombo = ListCombo()
    

    @IBOutlet weak var titleLab: UILabel!
    
    @IBOutlet weak var priceLab: UILabel!
    
    @IBOutlet weak var detailBtn: UIButton!
    
    @IBOutlet weak var describeLab: UILabel!
    
    var lastLabMaxY:CGFloat = 0
    
    class func projectSpecificationView()->SSProjectSpecificationView2{
        return Bundle.main.loadNibNamed("SSProjectSpecificationView2", owner: nil, options: nil)?.last as! SSProjectSpecificationView2
    }
    
   
    
    override func awakeFromNib() {
        super.awakeFromNib()
                                                             
        detailBtn.isUserInteractionEnabled = true
        detailBtn.addTarget(self, action: #selector(detailAction(_:)), for: .touchUpInside)
    }
    
    

    
    func setData(model:ListCombo) {
        self.model = model
        print("describeLab.frame.maxY0:\(describeLab.frame.maxY)")
        self.describeLab.text = model.illustration
    
        let font = self.describeLab.font
        let size = CGSize(width: ScreenWidth - 32, height: CGFloat.zero)
        let titleHeight = model.illustration.sizeWithText(font: font!, size: size).height
        self.describeLab.frame.size = CGSize(width: self.describeLab.frame.width, height: titleHeight)
        print("describeLab.frame.maxY1:\(describeLab.frame.maxY)")
        print("frame0:\(frame)")
        frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: frame.width, height: describeLab.frame.maxY)
        print("frame1:\(frame)")
        print("")
        
        detailBtn.isHidden = !(model.isDetails == "0")
        
    }
 
//    @IBAction func detailAction(_ sender: Any) {
//        let vc =  SSItemDetailViewController.init(nibName: "SSItemDetailViewController", bundle: nil)
//        vc.id = model.id
//        UIViewController.current().present(vc, animated: true)
//    }
    
    @objc func detailAction(_ sender: Any) {
        let vc =  SSItemDetailViewController.init(nibName: "SSItemDetailViewController", bundle: nil)
        vc.id = model.id
        UIViewController.current().present(vc, animated: true)
    }
    
}
